package com.easyui.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.easyui.bean.Student;
import com.easyui.common.SelNote;
import com.easyui.common.SelStudent;
import com.easyui.common.SelTeacher;

public class SonReplyServlet extends HttpServlet {
       
    public SonReplyServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
		

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/json;charset=utf-8");
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		boolean success = false;
		String msg = "";
		
		HttpSession session = request.getSession(); //获的session
		String role = (String)session.getAttribute("role");
		String userID = (String)session.getAttribute("userID");
		
		if(role != null && !role.trim().equals("")) {
			if(userID != null && !userID.trim().equals("")) {//session未过期
				String ncont = request.getParameter("ncont");
System.out.println("n:" + ncont);
				int rootid = Integer.parseInt(request.getParameter("rootid"));
				int pid = Integer.parseInt(request.getParameter("pid"));
				int pno = Integer.parseInt(request.getParameter("pno"));
				int sonreply = Integer.parseInt(request.getParameter("sonreply"));//是否已有回复
				
System.out.println("pid:" + pid);
				
				success = new SelNote().addSonReply(role, userID, pno, ncont, rootid, pid, sonreply);
				
			} else {
				success = false;
			}
		} else {
			success = false;
		}
		
		if(success) {
			msg = "ok";
		} else {
			msg = "error";
		}
		
		out.print(msg);
		out.flush();
		out.close();
	}

}
